package me.baicai.modules.belldandy.exception.rest;

import me.baicai.aop.log.Log;
import me.baicai.exception.domain.GcbException;
import me.baicai.modules.belldandy.exception.service.GcbExceptionService;
import me.baicai.modules.belldandy.exception.service.dto.GcbExceptionQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author 超级大白菜
* @date 2019-12-24
*/
@Api(tags = "GcbException管理")
@RestController
@RequestMapping("/api/gcbException")
public class GcbExceptionController {

    private final GcbExceptionService gcbExceptionService;

    public GcbExceptionController(GcbExceptionService gcbExceptionService) {
        this.gcbExceptionService = gcbExceptionService;
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, GcbExceptionQueryCriteria criteria) throws IOException {
        gcbExceptionService.download(gcbExceptionService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询GcbException")
    @ApiOperation("查询GcbException")
    public ResponseEntity getGcbExceptions(GcbExceptionQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(gcbExceptionService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增GcbException")
    @ApiOperation("新增GcbException")
    public ResponseEntity create(@Validated @RequestBody GcbException resources){
        return new ResponseEntity<>(gcbExceptionService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改GcbException")
    @ApiOperation("修改GcbException")
    public ResponseEntity update(@Validated @RequestBody GcbException resources){
        gcbExceptionService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping(value = "/{id}")
    @Log("删除GcbException")
    @ApiOperation("删除GcbException")
    public ResponseEntity delete(@PathVariable Integer id){
        gcbExceptionService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
